package com.ajhlp.spring_modules.file;

import javax.servlet.http.HttpSession;

import org.apache.commons.fileupload.ProgressListener;

public class FileUploadProgressListener implements ProgressListener {
	
	public final static String UPLOAD_PROGRESS_STATUS_KEY = "upload_progress_status";
	
	private HttpSession session;
	
	public FileUploadProgressListener(HttpSession session){
		this.session = session;
	}

	public void update(long pBytesRead, long pContentLength, int pItems) {
		// TODO Auto-generated method stub
		if(this.session != null){
			
			Double progress =  ((double)pBytesRead/pContentLength)*100;
			
			this.session.setAttribute(UPLOAD_PROGRESS_STATUS_KEY, progress.intValue());
		}
	}

}
